package dao;

import java.io.IOException;
import java.sql.*;
import java.util.ResourceBundle;

/**
 * 
 * @author Pascal Kuendig
 * @version 10.07.2013
 *
 */
public abstract class AbstractDAO {
	
	private Statement stmt;
	private ResultSet rs = null;

	/**
	 * Fuehrt einen Select-Query aus
	 * @param sqlStatement
	 * @return ResultSet
	 * @throws SQLException
	 */
	protected ResultSet executeSelectQueryWithResultSet(String sqlStatement) throws SQLException{
		stmt = ConnectionSingeltonDAO.getConnectionInstance().createStatement();
		rs = stmt.executeQuery(sqlStatement);
		return rs;
	}
	
	/**
	 * Fuehrt einen Insert/Update-Query aus
	 * @param sqlStatement
	 * @return insertResult 	0=no Insert 
	 * @throws SQLException
	 */
	protected int executeInsertQuery(String sqlStatement) throws SQLException {
		int insertResult;
		stmt = ConnectionSingeltonDAO.getConnectionInstance().createStatement();
		insertResult = stmt.executeUpdate(sqlStatement);
		//Statement schliessen
		stmt.close();
		return insertResult;
	}
	
	private ResourceBundle getPropertieInstance() throws IOException{
		return ResourceBundle.getBundle("properties.dao");
	}
	
	protected String getDaoPropertie(String keyWord) throws IOException{
		return getPropertieInstance().getString(keyWord);
	}
}
